﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RRRSRoguelike.Entities;
using System.Drawing;

namespace RRRSRoguelike.Managers
{
    class PropManager
    {

        #region variables
        private IList<Stairwell> stairwells;
        private IList<Sword> swords;

        public Tile LookTile;
        public Fireball Fireball; 
        #endregion

        #region methods
        public PropManager()
        {
            swords = new List<Sword>();
            Fireball = new Fireball(new Point(), Direction.N);
            LookTile = new Tile();
            stairwells = new List<Stairwell>();
            stairwells.Add(new Stairwell(DungeonManager.Instance.DungeonLevel.GetValidRandomPoint(), StepDirection.Up));
        }

        public void ClearProps()
        {
            swords.Clear();
            stairwells.Clear();
        }

        public void AddProps()
        {
            for (int i = 0; i < Constants.NumberOfSwords; i++)
            {
                Sword sword = new Sword(DungeonManager.Instance.DungeonLevel.GetValidRandomPoint());
                swords.Add(sword);
            }

            stairwells.Add(new Stairwell(DungeonManager.Instance.DungeonLevel.GetValidRandomPoint(), StepDirection.Up));

        }

        public Sword GetBestSword(Point location)
        {
            Sword sword;
            sword = swords.Where(s => s.Position == location).OrderBy(s => s.UsesRemaining).Last();
            return sword;
        }

        public void AddSword(Sword sword)
        {
            swords.Add(sword);
        }

        public void RemoveSword(Sword sword)
        {
            swords.Remove(sword);
        }

        public void PropsToTiles()
        {
            swords.ToList().ForEach(s => DungeonManager.Instance.DungeonLevel.AddTile(s,Layers.Prop));
            stairwells.ToList().ForEach(s => DungeonManager.Instance.DungeonLevel.AddTile(s,Layers.Prop));
            if (Fireball.Active) DungeonManager.Instance.DungeonLevel.AddTile(Fireball,Layers.Effect);
            if (LookTile.Active) DungeonManager.Instance.DungeonLevel.AddTile(LookTile, Layers.Effect); 
            //walls.ToList().ForEach(w => DungeonManager.Instance.DungeonLevel.AddWalls(w));
        }
        #endregion

    }
}
